const mongoose = require('mongoose')
      mongoose.Promise = Promise
         
mongoose.connect('mongodb://localhost/Answer-Question')

var db = mongoose.connection
db.on('open',function(){
	console.log('数据库已经连接上')
})
db.on('error',function(){
	console.log('数据库连接失败')
})

var Schema = mongoose.Schema
var userSchema = new Schema({
	username:String,
	password:String,
	email:String,
	curse:String,
	gender:Boolean,
	createTime:Date,
	header:String
})

var User = mongoose.model('users',userSchema)

var questionSchema = new Schema({
	content:String,
	createTime:Date,
	ans:Array,
	ownerId:{type:Schema.Types.ObjectId,ref:'users'},
	answerId:{type:Schema.Types.ObjectId,ref:'answers'}
})

var Question = mongoose.model('questiones',questionSchema)

var answerSchema = new Schema({
	username:String,
	content:String,
	createTime:Date,
	ownerId:{type:Schema.Types.ObjectId,ref:'users'},
	questionId:{type:Schema.Types.ObjectId,ref:'questiones'}
})

var Answer = mongoose.model('answers',answerSchema)

module.exports = {
	User,
	Answer,
	Question
}
